package com.ybwh.springboot1.conf.intercepter.login;

import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 内部接口的拦截器
 *
 * @author: Fan Beibei
 * @date: 2018/5/4 17:56
 * @Modified By:
 */
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {



    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (handler instanceof HandlerMethod) {//拦截controller方法
            HandlerMethod handlerMethod = (HandlerMethod) handler;
//            RequestMapping requestMappingOnMethod=handlerMethod.getMethod().getAnnotation(RequestMapping.class);
//            RequestMapping requestMappingOnClass = handlerMethod.getBeanType().getAnnotation(RequestMapping.class);
//            String pathOnClass = requestMappingOnClass.value()[0];
            
            LoginRequired loginRequired=handlerMethod.getMethod().getAnnotation(LoginRequired.class);
            if (null == loginRequired) {
            	loginRequired = handlerMethod.getBeanType().getAnnotation(LoginRequired.class);
			}
            
            
            if (null == loginRequired) {
				return true;
			}
            
            
            

           


        }


        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
